<template>
	
	<view>
		<u-sticky>
			
			<u-tabs
			:list="tabList" 
			@change="changeTab"
			active-color="#FD7885"
			height='88'
			bar-width='58'
			bar-height='4'
			item-width='375'
			style="border-bottom: 1px solid #EDEDED;border-top: 1px solid #EDEDED;"
			font-size='26'
			:current='tabCurrent'
			></u-tabs>
			
			
			<!-- <view class="w-100 bg-f u-p-t-12 u-p-l-32 u-p-m-10">
				<view class="u-m-b-16 row u-f-28">
					<view @click="getListDataByState(1)" class="flex-center u-bdr-28 tab-item "
						:class="state==1 ? 'bg-primary w-s-color-f' : ''">已上架</view>
					<view @click="getListDataByState(2)" class="flex-center u-bdr-28 tab-item "
						:class="state==2 ? 'bg-primary w-s-color-f' : ''">已下架</view>
				</view>
			</view> -->
		</u-sticky>
	
	<view class="course_list_container leader-view column">
		
		<view class="item" v-for="(item, index) in listData" :key='index'
			@click="goNav('/me/spreader/renwu/edit?spreadId='+item.id)+'&type=1'">
			<view class="pic_title align-center">
				<view class="pic_box">
					<image :src='item.titleImg' mode="aspectFill"></image>
				</view>
				<view class="title_box">
					<view class="name">{{item.title}}</view>
					<view class="label">推广金：<text  style="color: #FD7885;">¥{{item.goodsPrice}}</text></view>
					<view class="label">剩余库存：<text>{{item.endNum}}/{{item.sumNum}}</text></view>
					<view class="label">创建时间：<text>{{item.createTime}}</text></view>
				</view>
			</view>
			<!-- <view class="btn_box">
				<u-button type="error" size="mini" v-if="item.isPrice==1" @click.stop="updataInfo(item,1)">免费</u-button>
				<u-button type="error" size="mini" v-if="item.isPrice!=1" @click.stop="updataInfo(item,2)">收费</u-button>
				<u-button type="error" size="mini" v-if="item.good == 1" @click.stop="updataInfo(item,3)">下家</u-button>
				<u-button type="error" size="mini" v-if="item.good != 1" @click.stop="updataInfo(item,4)">推荐</u-button>
				<u-button type="error" size="mini" @click.stop="deleteItem(item.courseDetailsId,index)">删除</u-button>
				<u-button type="primary" size="mini"
					@click.stop="goNav('/me/create/video/edit?courseId='+item.courseId+'&courseDetailsId='+item.courseDetailsId+'&type=1')">修改</u-button>
			</view> -->
		</view>

		<view class="footer-btn" style="z-index: 9999;">
			<view class="usermain-btn" @click.stop="goNav('/me/spreader/renwu/edit')">发布新任务
			</view>
		</view>

		<u-loadmore v-if="listData.length > 0" :status="status" />
		<empty title="暂无任务" :isShow='false' v-if="listData.length==0"></empty>
	</view>
</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				listData: [],
				status: 'loadmore',
				page: 1,
				limit: 10,
				state: 1,
				title: null,
				tabList: [{
						name: '已上架',
					}, {
						name: '已下架',
				}],
				tabCurrent:0
				
			}
		},
		onLoad(option) {
			this.getListData()
		},
		onShow() {
			this.getListData()
		},
		methods: {
			changeTab(e){
				this.tabCurrent = e
				if (e==0){
					this.getListDataByState(1)
				}else{
					this.getListDataByState(2)
				}
			},
			getListDataByState(valText) {
				this.state = valText
				this.getListData()
			},
			updataInfo(item, indexNo) {
				var data = item;
				if (indexNo == 1) {
					item.isPrice = 2
				}
				if (indexNo == 2) {
					item.isPrice = 1
				}
				if (indexNo == 3) {
					item.good = 2
				}
				if (indexNo == 4) {
					item.good = 1
				}
				this.$u.post("/app/user/updateCourseDetailsByApp", data).then(res => {
					if (res.code === 0) {
						uni.showToast({
							title: '更新成功',
							icon: "none"
						})
						setTimeout(function() {
							this.getListData()
						}, 1000)
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				});

			},
			deleteItem(id, index) {
				var that = this
				uni.showModal({
					title: '提示',
					content: '是否确认删除该任务',
					success: function(res) {
						if (res.confirm) {
							that.$u.get("/app/user/deleteCourseDetailsByApp?ids=" + id).then(
								res => {
									if (res.code === 0) {
										that.listData.splice(index, 1)
										uni.showToast({
											title: '删除成功',
											icon: "none"
										})
									} else {

									}
								});


						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			getListData() {

				let data = {
					limit: this.limit,
					page: this.page,
					status: this.state,
					title: this.title
				}

				this.$u.get("/app/spreader/getProductInfoBySpPage", data).then(
					res => {
						if (res.code === 0) {
							this.pages = res.data.total
							if (this.page < this.pages) {
								this.status = 'loadmore'
							} else {
								this.status = 'nomore'
							}
							if (this.page == 1) {
								this.listData = res.data.records
							} else {
								this.listData = [...this.listData, ...res.data.list]
							}
						} else {
							uni.stopPullDownRefresh();
						}
					});


			},
			goNav(e) {
				uni.navigateTo({
					url: e
				})
			},
		},
		onReachBottom: function() {
			if (this.page < this.pages) {
				this.page += 1
				this.status = 'loading'
				this.getListData()

			} else {
				this.status = 'nomore'
			}

		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getListData()
		},

	}
</script>

<style>
	page {
		background: #F7F8FF;
	}
</style>
<style scoped lang="scss">
	.leader-view {
		width: 100vw;
		min-height: 100vh;
		padding-bottom: 24rpx;
		padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(24rpx + env(safe-area-inset-bottom));

		.tab-item {
			width: 136rpx;
			height: 44rpx;
			transition: all .3s;
		}

		.tag-view {
			width: 72rpx;
			height: 32rpx;
			background: #F1651A;
			border-radius: 0rpx 6rpx 0rpx 18rpx;
			line-height: 32rpx;
		}

		.index-view {
			padding: 4rpx 10rpx;
			background: #333333;
			border-radius: 12rpx 0rpx 12rpx 0rpx;
		}

		.hot-img {
			width: 32rpx;
			height: 32rpx;
			margin-right: 6rpx;
		}

		.tag-item {
			padding: 2rpx 10rpx;
		}
	}

	.footer-btn {
		padding-bottom: calc(20rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
		box-sizing: content-box;
		position: fixed;
		left: 0;
		bottom: 0;
		width: 750rpx;
		padding-top: 20rpx;
	}

	.footer-btn .usermain-btn {
		color: #FFFFFF;
		background: linear-gradient(90deg, #ff7581, #f8a5af);
		text-align: center;
		width: 686rpx;
		height: 80rpx;
		font-size: 28rpx;
		line-height: 80rpx;
		margin: 0 auto;
		border-radius: 40rpx;
	}

	.course_list_container {
		padding-bottom: calc(120rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
		padding-top: 20rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		.item {
			background: #FFFFFF;
			border-radius: 10;
			padding: 30rpx 20rpx;
			margin-bottom: 20rpx;

			.pic_title {
				display: flex;

				.pic_box{
					width: 160rpx;
					height: 160rpx;
					background: #F7F7F7;
					border-radius: 10rpx;
					margin-right: 20rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					image{
						width: 130rpx;
						height: 126rpx;
					}
				}

				.name {
					display: block;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					width:450rpx;
					font-weight: bold;
					font-size: 28rpx;
					color: #1A1A1A;
				}

				.label {
					font-weight: 500;
					font-size: 24rpx;
					color: #999999;
					padding-top: 12rpx;
					text {
						font-weight: 500;
						font-size: 24rpx;
						color: #333333;
					}
				}

				.type {
					border: 1px solid #8B8FF0;
					color: #8B8FF0;
					margin-right: 4rpx;
					padding-top: 6rpx;
					border-radius: 8rpx;
					font-size: 24rpx;
				}

				.label_text {
					font-weight: 400;
					font-size: 28rpx;
					color: #969696;
					// display:block;
					// white-space:nowrap;
					// overflow:hidden;
					// text-overflow:ellipsis;
					// width: 500rpx;
				}
			}

			.btn_box {
				display: flex;
				margin-top: 20rpx;
				justify-content: flex-end;

				button {
					margin: 0 !important;
					margin-left: 20rpx !important;
				}
			}
		}
	}
</style>